package com.newworld.dmsapp2.util;

import org.litepal.crud.DataSupport;

import android.content.Context;
import android.util.Log;

import com.newworld.dmsapp2.bean.Register;
import com.newworld.dmsapp2.bean.User;

public class SingleSample {
	private static SingleSample singleSample = null;
	private User user;
	private Register register;
	Context context;

	public static synchronized SingleSample getInstance(Context context) {

		if (singleSample == null)
			singleSample = new SingleSample(context);
		return singleSample;
	}

	private SingleSample(Context context) {
		this.context = context;
		user = DataSupport.find(User.class, MyPreference.getInstance(context)
				.getUserId(), true);
		Log.e("SingSample 用户不存在", "user的id为"
				+ MyPreference.getInstance(context).getUserId() + "");
	}

	public User getUser() {

		return user;
	}

	public Register getRegister() {

		return register;
	}

	public static synchronized void resetInstance() {
		if (null != singleSample) {
			singleSample.user = DataSupport.find(User.class, MyPreference
					.getInstance(singleSample.context).getUserId(), true);
		}
	}

	public static synchronized void resetInstance1() {
		if (null != singleSample) {
			singleSample.register = DataSupport.find(Register.class,
					MyPreference.getInstance(singleSample.context)
							.getRegisterrId(), true);
		}
	}

}
